{
 "metadata": {
  "name": "",
  "signature": "sha256:6fc3776472162001776d8c22a8b45276a2be453abfe13d3e00af64ec264b69ed"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import sys\n",
      "sys.path.append('../protobufs')\n",
      "import sdtCommands_pb2\n",
      "import time\n",
      "from IPython.html import widgets\n",
      "from IPython.display import display\n",
      "from google.protobuf import text_format\n",
      "import socket\n",
      "delay=0\n",
      "sdt_addr=\"127.0.0.1\"\n",
      "sdt_port=50000\n",
      "sdtsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n",
      "\n",
      "# Init SDT3d socket and connect\n",
      "sdtsock.connect((sdt_addr,int(sdt_port)))\n",
      "print \"Connecting to \" + sdt_addr + \"/\" + str(sdt_port)\n",
      "\n",
      "node = sdtCommands_pb2.Node()\n",
      "\n",
      "# setup a protobuffer\n",
      "node.name = \"node1\"\n",
      "node.type = \"man\"\n",
      "node.position.lat = -120.8026\n",
      "node.position.lon = 35.7528\n",
      "node.position.alt = 50000\n",
      "\n",
      "nodeStr =  \"node \" + node.name + \" pos \" + str(node.position.lat) + \",\" \\\n",
      "+ str(node.position.lon) + \" type \" + node.type + \" symbol sphere,blue \" \n",
      "print nodeStr\n",
      "\n",
      "\n",
      "sdtsock.sendall(node.SerializeToString())\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Connecting to 127.0.0.1/50000\n",
        "node node1 pos -120.8026,35.7528 type man symbol sphere,blue \n"
       ]
      }
     ],
     "prompt_number": 110
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def status(cmd):\n",
      "    send_cmd('status \"' + cmd + '\"')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 111
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def send_cmd(cmd):\n",
      "    print cmd\n",
      "    sdtsock.sendall(' ' + cmd + ' ')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 112
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# set background bounds \n",
      "#send_cmd(\"bgbounds -120.8091,35.7414,-120.768,35.7646\")\n",
      "\n",
      "# send command to sdt3d status pane\n",
      "#status(nodeStr)\n",
      "\n",
      "# send command over regular socket\n",
      "#send_cmd(nodeStr)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 113
    }
   ],
   "metadata": {}
  }
 ]
}